def easy(n):
        for i in range(2,n):
                if n % i == 0:
                        return False
        return True

a = input()
digitals = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
left = []
right = []
s = a.split()
b = ""

if len(s) == 3 and s[0] in digitals and s[1] in digitals and s[2] in digitals:
        for i in s:
                b += str(digitals.index(i))
        b = int(b)
        for i in range(2, b):
                if easy(i):
                        left.append(i)
        for i in range(b, 1010):
                if easy(i):
                        right.append(i)
        count1 = b - left[-1]
        count2 = right[0] - b
        if count1 < count2:
                print(left[-1])
        else:
                print(right[0])
else:
        print("Wrong input")